home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MISC.SWG / 0091_Going International.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-25  |  5KB  |  221 lines

  1. unit CaseUtil;
  2.  
  3. interface
  4.  
  5. type
  6.   DelimType =
  7.     record
  8.       thousands,
  9.       decimal,
  10.       date,
  11.       time           : array[0..1] of Char;
  12.     end;
  13.  
  14.   CurrType       = (leads,             { symbol precedes value }
  15.                     trails,            { value precedes symbol }
  16.                     leads_,            { symbol, space, value }
  17.                     _trails,           { value, space, symbol }
  18.                     replace);          { replaced }
  19.  
  20.   CountryType =
  21.     record
  22.       DateFormat     : Word;           { 0: USA, 1: Europe, 2: Japan }
  23.       CurrSymbol     : array[0..4] of Char;
  24.       Delimiter      : DelimType;      { Separators }
  25.       CurrFormat     : CurrType;       { Way currency is formatted }
  26.       CurrDigits     : Byte;           { Digits in currency }
  27.       Clock24hrs     : Boolean;        { True if 24-hour clock }
  28.       CaseMapCall    : procedure;      { Lookup table for ASCII > $80 }
  29.       DataListSep    : array[0..1] of Char;
  30.       CID            : word;
  31.       Reserved       : array[0..7] of Char;
  32.     end;
  33.  
  34.   CountryInfo =
  35.     record
  36.       case InfoID: byte of
  37.       1: (IDSize     : word;
  38.           CountryID  : word;
  39.           CodePage   : word;
  40.       TheInfo    : CountryType);
  41.       2: (UpCaseTable: pointer);
  42.       end;
  43.  
  44. var
  45.   CountryOk : Boolean;            { Could determine country code flag }
  46.   CountryRec    : CountryInfo;
  47.  
  48. function Upcase(c : Char) : Char;
  49. function LoCase(c : Char) : Char;
  50. function UpperStr(s : string) : string;
  51. function LowerStr(s : string) : string;
  52. procedure UpCaseStr(var s : String);
  53. procedure LoCaseStr(var s : String);
  54.  
  55. implementation
  56.  
  57. {$R-,S-,V- }
  58. var
  59.   LoTable   : array[0..127] of byte;
  60.   CRP, LTP  : pointer;
  61.  
  62.   { Convert a character to upper case }
  63.   function Upcase; Assembler; asm
  64.     mov     al, c
  65.     cmp     al, 'a'
  66.     jb      @2
  67.     cmp     al, 'z'
  68.     ja      @1
  69.     sub     al, ' '
  70.     jmp     @2
  71. @1: cmp     al, 80h
  72.     jb      @2
  73.     sub     al, 7eh
  74.     push    ds
  75.     lds     bx,CountryRec.UpCaseTable
  76.     xlat
  77.     pop     ds
  78. @2:
  79.   end;                                 { UpCase }
  80.  
  81.   { Convert a character to lower case }
  82.   function LoCase; Assembler;  asm
  83.     mov     al, c
  84.     cmp     al, 'A'
  85.     jb      @2
  86.     cmp     al, 'Z'
  87.     ja      @1
  88.     or      al, ' '
  89.     jmp     @2
  90. @1: cmp     al, 80h
  91.     jb      @2
  92.     sub     al, 80h
  93.     mov     bx,offset LoTable
  94.     xlat
  95. @2:
  96.   end;                                 { LoCase }
  97.  
  98.   { Convert a string to uppercase }
  99.   procedure UpCaseStr; Assembler;  asm
  100.     cld
  101.     les     di, s
  102.     xor     ax, ax
  103.     mov     al, es:[di]
  104.     stosb
  105.     xchg    ax, cx
  106.     jcxz    @4
  107.     push    ds
  108.     lds     bx,CountryRec.UpCaseTable
  109. @1: mov     al, es:[di]
  110.     cmp     al, 'a'
  111.     jb      @3
  112.     cmp     al, 'z'
  113.     ja      @2
  114.     sub     al, ' '
  115.     jmp     @3
  116. @2: cmp     al, 80h
  117.     jb      @3
  118.     sub     al, 7eh
  119.     xlat
  120. @3: stosb
  121.     loop    @1
  122.     pop     ds
  123. @4:
  124.   end;                                 { UpCaseStr }
  125.  
  126.   { Convert a string to lower case }
  127.   procedure LoCaseStr; Assembler;  asm
  128.     cld
  129.     les     di, s
  130.     xor     ax, ax
  131.     mov     al, es:[di]
  132.     stosb
  133.     xchg    ax, cx
  134.     jcxz    @4
  135. @1: mov     al, es:[di]
  136.     cmp     al, 'A'
  137.     jb      @3
  138.     cmp     al, 'Z'
  139.     ja      @2
  140.     or      al, ' '
  141.     jmp     @3
  142. @2: cmp     al, 80h
  143.     jb      @3
  144.     sub     al, 80h
  145.     mov     bx, offset LoTable
  146.     xlat
  147. @3: stosb
  148.     loop    @1
  149. @4:
  150.   end;                                 { LoCaseStr }
  151.  
  152. function UpperStr(s : string) : string;
  153. begin  UpCaseStr(s);  UpperStr:=s end;
  154. function LowerStr(s : string) : string;
  155. begin  LoCaseStr(s);  LowerStr:=s end;
  156.  
  157. begin                                  { init DoCase unit }
  158.   CRP := @CountryRec;
  159.   LTP := @LoTable;
  160.   asm
  161.  
  162.     { Exit if Dos version < 3.0 }
  163.     mov     ah, 30h
  164.     int     21h
  165.     cmp     al, 3
  166.     jb      @1
  167.  
  168.     { Call Dos 'Get country dependent information' function }
  169.     mov     ax, 6501h
  170.     les     di, CRP
  171.     mov     bx,-1
  172.     mov     dx,bx
  173.     mov     cx,41
  174.     int     21h
  175.     jc      @1
  176.  
  177.     { Call Dos 'Get country dependent information' function }
  178.     mov     ax, 6502h
  179.     mov     bx, CountryRec.CodePage
  180.     mov     dx, CountryRec.CountryID
  181.     mov     CountryRec.TheInfo.CID, dx
  182.     mov     cx, 5
  183.     int     21h
  184.     jc      @1
  185.  
  186.     { Build LoCase table }
  187.     les     di, LTP
  188.     mov     cx, 80h
  189.     mov     ax, cx
  190.     cld
  191. @3:
  192.     stosb
  193.     inc     ax
  194.     loop    @3
  195.     mov     di, offset LoTable - 80h
  196.     mov     cx, 80h
  197.     mov     dx, cx
  198.     push    ds
  199.     lds     bx, CountryRec.UpCaseTable
  200.     sub     bx, 7eh
  201. @4:
  202.     mov     ax, dx
  203.     xlat
  204.     cmp     ax, 80h
  205.     jl      @5
  206.     cmp     dx, ax
  207.     je      @5
  208.     xchg    bx, ax
  209.     mov     es:[bx+di], dl
  210.     xchg    bx, ax
  211. @5:
  212.     inc     dx
  213.     loop    @4
  214.     pop     ds
  215.     mov     [CountryOk], True
  216.     jmp     @2
  217. @1: mov     [CountryOk], False
  218. @2:
  219.   end;
  220. end.
  221.